import { Inject, Get, Query } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { DoctorInfoEntity } from '../../entity/info';
import { DoctorInfoService } from '../../service/info';
import { In } from 'typeorm';

/**
 * 医生信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: DoctorInfoEntity,
  service: DoctorInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['a.name'],
    fieldEq: ['a.department', 'a.title'],
    where: async ctx => {
      const { startTime, endTime } = ctx.request.body;
      const where = [];
      if (startTime) {
        where.push(['a.receptionTime >= :startTime', { startTime }]);
      }
      if (endTime) {
        where.push(['a.receptionTime <= :endTime', { endTime }]);
      }
      return where;
    },
  },
})
export class AdminDoctorInfoController extends BaseController {
  @Inject()
  doctorInfoService: DoctorInfoService;

  @Get('/getSelectlist', { summary: '获取医生列表' })
  async getSelectlist(@Query('shopId') shopId: number) {
    const doctors = await this.doctorInfoService.getSelectlist(shopId);
    return this.ok(doctors)
  }
}
